package cn.com.landsky.alarm.controller;

import cn.com.landsky.alarm.entity.AlarmMessage;
import cn.com.landsky.alarm.service.AlarmMessageService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 ** @category 请用一句话来描述其用途...
 ** @author qing.yunhui
 ** @email: qingyunhui@fentuan360.com
 ** @createTime: 2019/1/7-16:03
 **/
@RestController
@RequestMapping(value="/alarmMessage")
@Slf4j
@Api(value = "AlarmMessageController", description = "一键呼叫消息控制器")
public class AlarmMessageController {

    @Autowired
    AlarmMessageService alarmMessageService;

    // ==============================================================> 一键呼叫（消息） ==============================================================>


    @RequestMapping(value="/addMessage.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "添加一键呼叫消息")
    public String addMessage(AlarmMessage alarmMessage){
        int count=alarmMessageService.save(alarmMessage);
        log.info("=============>调用 add 方法，受影响的行数:{}条。",new Object[]{count});
        return "ok";
    }

    @RequestMapping(value="/deleteMessage.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "删除一键呼叫消息")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "java.lang.Long", name = "id", value = "id", required = true)})
    public String deleteMessage(Long id){
        int count=alarmMessageService.deleteById(id);
        log.info("=============>调用 delete 方法，受影响的行数:{}条。",new Object[]{count});
        return "ok";
    }

    @RequestMapping(value="/updateMessage.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "更新一键呼叫消息")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "java.lang.Long", name = "id", value = "id", required = true)})
    public String updateMessage(AlarmMessage alarmMessage){
        int count=alarmMessageService.update(alarmMessage);
        log.info("=============>调用 upadte 方法，受影响的行数:{}条。",new Object[]{count});
        return "ok";
    }

    @RequestMapping(value="/queryMessage.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "查询一键呼叫消息")
    public String queryMessage(AlarmMessage alarmMessage){
        List<AlarmMessage> alarmMessageList=alarmMessageService.query(alarmMessage);
        log.info("=============>调用 query 方法.");
        return JSONObject.toJSONString(alarmMessageList);
    }

}
